Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add global or import scripts into DOM #1030

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sagardspeed2
Copy link
Contributor

Describe your changes

Add global or import scripts into DOM to reduce the load on buildEvaluateFunction

Screenshots [Optional]

Issue ticket number and link

Closes #1027

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have added tests
  • I have added a changeset pnpm changeset add
  • I have added example usage in the kitchen sink app

Copy link
Contributor

github-actions bot commented Feb 7, 2025

Visit the preview URL for this PR (updated for commit cc73007):

https://react-kitchen-sink-dev--pr1030-1027-add-global-and-mit9l9lq.web.app

(expires Tue, 25 Feb 2025 18:52:03 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 6267897ade2ba783b6db70a53a60fc3946d625e9

@sagardspeed2 sagardspeed2 self-assigned this Feb 8, 2025
Copy link

changeset-bot bot commented Feb 10, 2025

⚠️ No Changeset found

Latest commit: cc73007

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines 101 to 102
${importedScripts || ""}
${globalBlock || ""}
Copy link
Contributor

@evshi evshi Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to wrap this in a function that will be unique by screen. When the script loads, it should execute this function that returns a closure object with a function to eval, with an expression and context.

It should look like this

// script tag content, rename unique by screen
const createEvalClosure = () => {
  // importedScripts
  // globalScripts
  
  return (expression, context) => {
     // evalCode
  }
}

const evalInClosure = createEvalClosure()
  
// elsewhere
evalInClosure(expression, context)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will still need to define ensemble in the window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve performance with large global scripts
2 participants